home *** CD-ROM | disk | FTP | other *** search
/ Freelog 22 / freelog 22.iso / Prog / Djgpp / GPC2952B.ZIP / lib / gcc-lib / djgpp / 2.952 / units / heapmon.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-02-08  |  2.4 KB  |  78 lines

  1. {
  2. A unit to watch the heap, i.e. check if all pointers that were
  3. allocated are released again. This is meant as a debugging help
  4. for avoiding memory leaks.
  5.  
  6. Use it in the main program before all other units. When, at the
  7. end of the program, some pointers that were allocated, have not
  8. been released, the unit prints a message to StdErr. Only pointers
  9. allocated via the Pascal mechanisms (New, GetMem) are tracked, not
  10. pointers allocated with direct libc calls or from C code. After a
  11. runtime error, pointers are not checked.
  12.  
  13. Note that many units and libraries allocate memory for their own
  14. purposes and don't always release it at the end. Therefore, the
  15. usefulness of this unit is rather limited.
  16.  
  17. Copyright (C) 1998-2001 Free Software Foundation, Inc.
  18.  
  19. Author: Frank Heckenbach <frank@pascal.gnu.de>
  20.  
  21. This file is part of GNU Pascal.
  22.  
  23. GNU Pascal is free software; you can redistribute it and/or modify
  24. it under the terms of the GNU General Public License as published by
  25. the Free Software Foundation; either version 2, or (at your option)
  26. any later version.
  27.  
  28. GNU Pascal is distributed in the hope that it will be useful,
  29. but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31. GNU General Public License for more details.
  32.  
  33. You should have received a copy of the GNU General Public License
  34. along with GNU Pascal; see the file COPYING. If not, write to the
  35. Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  36. 02111-1307, USA.
  37.  
  38. As a special exception, if you link this file with files compiled
  39. with a GNU compiler to produce an executable, this does not cause
  40. the resulting executable to be covered by the GNU General Public
  41. License. This exception does not however invalidate any other
  42. reasons why the executable file might be covered by the GNU General
  43. Public License.
  44. }
  45.  
  46. {$gnu-pascal,B-,I-}
  47.  
  48. unit HeapMon;
  49.  
  50. interface
  51.  
  52. uses GPC;
  53.  
  54. { This unit has an empty interface. It is automatically activated
  55.   when used. }
  56.  
  57. implementation
  58.  
  59. var
  60.   HeapMonitorMark : Pointer = nil;
  61.  
  62. to begin do
  63.   Mark (HeapMonitorMark);
  64.  
  65. to end do
  66.   if (HeapMonitorMark <> nil) and (ErrorAddr = nil) then
  67.     begin
  68.       var Count : SizeType = ReleaseCount (HeapMonitorMark);
  69.       if Count <> 0 then
  70.         begin
  71.           RestoreTerminal (True);
  72.           Writeln (StdErr, 'Heap monitor: ', Count, ' pointer(s) were not disposed.');
  73.           Halt (7)
  74.         end
  75.     end;
  76.  
  77. end.
  78.